let compare a b =
 if a > b then 1 
 else 
   if a = b then 0
   else -1;;

let rec find someone = function
    [] -> failwith "cette personne n'existe pas"
  | (e1,e2)::l -> 
    if  someone = e1 then e2
    else find someone l;;

let rec add (name,count) = function 
[] -> (name,count)::[]
  | (e1,e2)::l when  (String.lowercase e1) = (String.lowercase name) -> (e1,e2)::l
  | (e1,e2)::l -> 
    if (String.lowercase e1) < (String.lowercase name) then (e1,e2)::(add (name,count) l)
    else (e1,e2)::(name,count):: l;;

let rec delete name l = 
  match l with
  [] -> []
  | (e1,e2)::l ->
    if e1 = name then l 
    else (e1,e2)::(delete name l);;

let rec update name count = function
[] -> []
  | (e1,e2)::l ->
    if e1 = name then (e1,count)::l
    else (e1,e2)::(update name count l);;

let rec name actualname changedname l = match l with
[] -> []
  | (e1,e2)::l -> 
    if e1 = actualname then (add (changedname,e2) (delete actualname l))
    else add (e1,e2) (name actualname changedname l);;

let rec map f = function 
[] -> []
  |e::l -> f(e)::(map f l);;

let rec sales l x = match l with
[] -> []
  | (e1,e2)::l -> (e1,e2-.(e2/.x))::(sales l x);;

let rec fusion (l1,l2) = match (l1,l2) with
    ([],[]) -> []
  | ([],l2) -> l2
  | (l1,[]) -> l1
  | ((e1,e2)::l3,(e3,e4)::l4) -> 

    if e1=e3 then (e1,e2+.e4)::(fusion (l3,l4))
    else 
      if e1 < e3 then (e1,e2)::(e3,e4)::(fusion (l3,l4))
      else (e3,e4)::(e1,e2)::(fusion (l3,l4));;
